import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import service from '@assets/js/API'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Validate from '@assets/js/filterRules'
import '@assets/js/mock.api'; // 接口API
import '@assets/css/element-variables.scss'; // 接口API

Vue.prototype.$axios=service;
Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(Validate);


router.beforeEach((to,from,next)=>{
  const token=localStorage.getItem('accessToken');
  Vue.prototype.$auth = JSON.parse(localStorage.getItem('userInfo'));
  if(to.matched.some(record => record.meta.requireAuth)){
    next()//如果路由中有meta的requireAuth，且为true，就不进行登录验证，否则进行登录验证
  }else{
    if(token){
      next()
    }else{
      if(to.path==="/login"){
        next()
      }else{
        next({path:'/login'})
      }
    }
  }
});
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
